package com.ymr.iot.consumer.listener;

import com.ymr.iot.consumer.service.IotMessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.jms.Message;
import javax.jms.MessageListener;

@Component
public class IotMessageListener implements MessageListener {
    private final static Logger logger = LoggerFactory.getLogger(IotMessageListener.class);

    @Autowired
    private IotMessageService iotMessageService;

    @Override
    public void onMessage(Message message) {
        try {

            //2.建议异步处理收到的消息，确保onMessage函数里没有耗时逻辑。
            // 如果业务处理耗时过程过长阻塞住线程，可能会影响SDK收到消息后的正常回调。
            iotMessageService.processMessage(message);
        } catch (Exception e) {
            logger.error("提交任务时出错，原因：[{}]", e);
        }
    }
}
